﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;

namespace GieldaCSharp
{
    class WykresOsie : Wykres
    {
        private List<Label> listLabel = new List<Label>();

        public WykresOsie(List<Label> _listLabel, List<kursV> _lista, Border _b, int _iOd)
        {
            lista = _lista;
            listLabel = _listLabel;
            iOd = _iOd;
            b = _b;
        }

        private void DrawXtics(PictureBox p, Graphics g, int N)
        {
            double Ln = (b.maxXn - b.minXn) / b.liczbaPodzialek; // Odstepy na osi x
            double L = N / b.liczbaPodzialek; // Ostepy miedzy danymi

            for (int i = 0; i <= b.liczbaPodzialek; i++)
            {
                // Opisuje os x
                Point point = new Point();

                point.X = Convert.ToInt32(i * Ln);
                point.Y = b.maxYn + 5;

                string str = data.wezDateDD_MM_YY(lista[Convert.ToInt32(i * L) + iOd].dataInt);

                listLabel[i].Location = point;
                listLabel[i].Text = str;

                // Rysuje linie pionowe siatki grid
                Point min = new Point();
                Point max = new Point();

                min.X = point.X + b.minXn;
                min.Y = b.minYn + 1;

                max.X = point.X + b.minXn;
                max.Y = b.maxYn - 1;

                if (0 != i && b.liczbaPodzialek != i) g.DrawLine(new Pen(Color.FromArgb(232, 232, 232)), min, max);
            }
        }

        private void DrawYtics(PictureBox p, Graphics g, double maxY, double minY)
        {
            double liczbaPodzialek = 10;
            double maxYtics = maxY;
            double minYtics = minY;

            double Ln = (b.maxYn - b.minYn) / liczbaPodzialek; // Odstepy na osi y
            double L = (maxYtics - minYtics) / liczbaPodzialek; // Ostepy miedzy danymi          

            for (int i = 0; i <= liczbaPodzialek; i++)
            {
                // Opisuje os y
                Point point = new Point();

                point.X = b.maxXn + 5; ;
                point.Y = ((b.maxYn - b.minYn) - (Convert.ToInt32(i * Ln)));

                string str = String.Format("{0:f}", (minYtics + (i * L)));

                Point pointLabel = new Point();
                pointLabel = point;
                pointLabel.Y -= 2;

                listLabel[i + 16].Location = pointLabel;
                listLabel[i + 16].Text = str;

                // Rysuje linie poziome siatki grid
                Point min = new Point();
                Point max = new Point();

                min.X = b.minXn + 1;
                min.Y = point.Y + b.minYn;

                max.X = b.maxXn - 1;
                max.Y = point.Y + b.minYn;

                if (0 != i && liczbaPodzialek != i) g.DrawLine(new Pen(Color.FromArgb(232, 232, 232)), min, max);
            }
        }

        public override void Draw(PictureBox p, Graphics g, double maxY, double minY, int N)
        {
            DrawXtics(p, g, N);
            DrawYtics(p, g, maxY, minY);
        }
    }
}
